home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Snippets / Sound / SndPlayDoubleBuffer / _headers / WAVE.h < prev   
Encoding:
C/C++ Source or Header  |  1996-11-15  |  5.8 KB  |  223 lines  |  [TEXT/CWIE]

  1. /*
  2. **    Apple Macintosh Developer Technical Support
  3. **
  4. **    Header information needed to parse Microsoft's WAVE formatted sounds.
  5. **
  6. **    by Mark Cookson, Apple Developer Technical Support
  7. **
  8. **    File:    WAVE.h
  9. **
  10. **    Copyright ©1996 Apple Computer, Inc.
  11. **    All rights reserved.
  12. **
  13. **    You may incorporate this sample code into your applications without
  14. **    restriction, though the sample code has been provided "AS IS" and the
  15. **    responsibility for its operation is 100% yours.  However, what you are
  16. **    not permitted to do is to redistribute the source as "Apple Sample
  17. **    Code" after having made changes. If you're going to re-distribute the
  18. **    source, we require that you make it clear in the source that the code
  19. **    was descended from Apple Sample Code, but that you've made changes.
  20. */
  21.  
  22. /* This was made from reading a document called wave.pdf which is an excerpt from
  23.    RIFFMCI.RTF, "Multimedia Programming Interface and Data Specification v1.0".
  24.  
  25.    This code does what I need, and worked with the WAVE files I had handy.
  26.    It may not work in all cases.
  27. */
  28.  
  29. #ifndef __WAVE__
  30. #define __WAVE__
  31.  
  32. #include <Errors.h>
  33. #include <Files.h>
  34. #include <Sound.h>
  35. #include <Types.h>
  36.  
  37. #ifndef __SOUNDSTRUCT__
  38. #include "SoundStruct.h"
  39. #endif
  40.  
  41. #ifndef __DBFFERRORS__
  42. #include "DBFF_Errors.h"
  43. #endif
  44.  
  45. #ifndef __SETUPDBHEADER__
  46. #include "SetupDBHeader.h"
  47. #endif
  48.  
  49. #ifndef __DEFINES__
  50. #include "Defines.h"
  51. #endif
  52.  
  53. #define kWAVEFORMID                (1<<0)
  54. #define kWAVEID                    (1<<1)
  55. #define kFormatID                (1<<2)
  56. #define kWAVEListID                (1<<3)
  57. #define kSilenceID                (1<<4)
  58. #define kCueID                    (1<<5)
  59. #define kFactID                    (1<<6)
  60. #define kPlaylistID                (1<<7)
  61. #define kAssocDataID            (1<<8)
  62. #define kLabelID                (1<<9)
  63. #define kNoteID                    (1<<10)
  64. #define kTextWithLenID            (1<<12)
  65. #define kEmbededFileID            (1<<13)
  66. #define kWAVEDataID                (1<<14)
  67.  
  68. enum {
  69.     WAVEFORMID                    = 'RIFF',
  70.     WAVEID                        = 'WAVE',
  71.     FormatID                    = 'fmt ',
  72.     WAVEListID                    = 'wavl',
  73.     SilenceID                    = 'slnt',
  74.     CueID                        = 'cue ',
  75.     FactID                        = 'fact',
  76.     PlaylistID                    = 'plst',
  77.     AssocDataID                    = 'adtl',
  78.     LabelID                        = 'labl',
  79.     NoteID                        = 'note',
  80.     TextWithLenID                = 'ltxt',
  81.     EmbededFileID                = 'file',
  82.     WAVEDataID                    = 'data'
  83. };
  84.  
  85. #define WAVE_FORMAT_PCM        (0x0001)        /* Microsoft Pulse Code Modulation (PCM) format */
  86. #define WAVE_FORMAT_ADPCM    (0x0002)        /* A WAVE Adaptive Differential Pulse Code Modulation file I saw once */
  87. #define WAVE_FORMAT_MULAW    (0x0007)        /* A WAVE mu-law file that I saw once */
  88. #define WAVE_FORMAT_IMA        (0x0011)        /* A WAVE IMA4 file that I saw once */
  89. #define IBM_FORMAT_MULAW    (0x0101)        /* IBM mu-law format */
  90. #define IBM_FORMAT_ALAW        (0x0102)        /* IBM a-law format */
  91. #define IBM_FORMAT_ADPCM    (0x0103)        /* IBM AVC Adaptive Differential Pulse Code Modulation format */
  92. #define kWAVEChunkBufferSize    128
  93.  
  94. typedef unsigned long ID;
  95.  
  96. typedef struct WAVEChunkHeader {
  97.     ID                    ckID;
  98.     long                fileSize;
  99. }WAVEChunkHeader;
  100.  
  101. typedef struct WAVEContainerChunk {
  102.     ID                    ckID;
  103.     long                ckSize;
  104.     ID                    formType;
  105. }WAVEContainerChunk;
  106.  
  107. typedef struct fmtChunk {
  108.     ID                    ckID;
  109.     long                ckSize;
  110.     short                wFormatTag;            /* Number indicating WAVE format category */
  111.     short                wChannels;            /* Number of channels 1 for mono 2 for stereo */
  112.     long                dwSamplesPerSec;    /* Sampling rate in samples per second */
  113.     long                dwAvgBytesPerSec;    /* Average number of bytes per second (could be used to estimate buffer sizes) */
  114.     short                wBlockAlign;        /* Block alignment in bytes of the waveform data, always process an integer multiple of this number */
  115. }fmtChunk;
  116.  
  117. typedef struct PCMFmtSpecChunk {
  118.     ID                    ckID;
  119.     long                ckSize;
  120.     short                wBitsPerSample;        /* Sample size */
  121. }PCMFmtSpecChunk;
  122.  
  123. typedef struct factChunk {
  124.     ID                    ckID;
  125.     long                ckSize;
  126.     long                dwFileSize;            /* Number of samples */
  127. }factChunk;
  128.  
  129. typedef struct cuePointsChunk {
  130.     ID                    ckID;
  131.     long                ckSize;
  132.     long                dwCuePoints;        /* Count of cue points */
  133.     /* There may be multiple number of these */
  134.     long                dwName;
  135.     long                dwPosition;
  136.     long                fccChunk;
  137.     long                dwChunkStart;
  138.     long                dwBlockStart;
  139.     long                dwSampleOffset;
  140. }cuePointsChunk;
  141.  
  142. typedef struct playlistChunk {
  143.     ID                    ckID;
  144.     long                ckSize;
  145.     long                dwSegments;            /* Count of play segments */
  146.     /* There may be multiple number of these */
  147.     long                dwName;
  148.     long                dwLength;
  149.     long                dwLoops;
  150. }playlistChunk;
  151.  
  152. //typedef struct waveDataChunk {
  153. //    ID                    ckID;
  154. //    short                something;            /* I don't know what this is */
  155. //}waveDataChunk;
  156.  
  157. typedef struct labelChunk {
  158.     ID                    ckID;
  159.     long                dwName;
  160.     char                data[1];            /* This is a null terminated string */
  161. }labelChunk;
  162.  
  163. typedef struct noteChunk {
  164.     ID                    ckID;
  165.     long                ckSize;
  166.     long                dwName;
  167.     char                data[1];            /* This is a null terminated string */
  168. }noteChunk;
  169.  
  170. typedef struct ltxtChunk {
  171.     ID                    ckID;
  172.     long                ckSize;
  173.     long                dwName;
  174.     long                dwSampleLength;
  175.     long                dwPurpose;
  176.     short                wCountry;
  177.     short                wLanguage;
  178.     short                wDialect;
  179.     short                wCodePage;
  180.     char                data[1];            /* This is a null terminated string */
  181. }ltxtChunk;
  182.  
  183. typedef struct fileChunk {
  184.     ID                    ckID;
  185.     long                ckSize;
  186.     long                dwName;
  187.     long                dwMedType;
  188.     char                data[1];            /* This is a null terminated string */
  189. }fileChunk;
  190.  
  191. typedef struct assocDataListChunk {
  192.     ID                    ckID;
  193.     long                ckSize;
  194.     labelChunk            labelInfo;
  195.     noteChunk            noteInfo;
  196.     ltxtChunk            ltxtInfo;
  197.     fileChunk            fileInfo;
  198. }assocDataListChunk;
  199.  
  200. typedef union {
  201.     WAVEChunkHeader            generic;
  202.     WAVEContainerChunk        container;
  203.     fmtChunk                fmt;
  204.     factChunk                fact;
  205.     cuePointsChunk            cuePoints;
  206.     playlistChunk            playList;
  207.     assocDataListChunk        assocData;
  208. //    waveDataChunk            waveData;
  209.     PCMFmtSpecChunk            waveData;
  210. }WAVETemplate, *WAVETemplatePtr;
  211.  
  212. OSErr        ASoundGetWAVEHeader        (SoundInfoPtr theSoundInfo,
  213.                                     long *dataStart,
  214.                                     long *length);
  215.  
  216. short        SwapShort                (const short theShort);
  217. long        SwapLong                (const long theLong);
  218. long        ReverseLong                (const long theLong);
  219.  
  220. #define stillMoreDataWAVEToRead        ((chunkFlags & kWAVEFORMID) && (!(chunkFlags & kFormatID) || !(chunkFlags & kWAVEDataID)) && (err == noErr))
  221.  
  222. #endif
  223.